{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import k3d\n",
    "import vtk\n",
    "import numpy as np\n",
    "from k3d.helpers import download\n",
    "import ipywidgets as widgets\n",
    "\n",
    "filename = download('https://github.com/To-Fujita/Babylon.js_3D_Graphics/raw/master/scenes/stl/Cute%20Darth%20Vader.stl')\n",
    "\n",
    "reader = vtk.vtkSTLReader()\n",
    "reader.SetFileName(filename)\n",
    "reader.Update()\n",
    "\n",
    "qualityFilter = vtk.vtkMeshQuality()\n",
    "qualityFilter.SetInputData(reader.GetOutput()) \n",
    "qualityFilter.SetTriangleQualityMeasureToArea()\n",
    "qualityFilter.SetQuadQualityMeasureToArea()\n",
    "qualityFilter.Update()\n",
    "\n",
    "plot = k3d.plot()\n",
    "plot += k3d.vtk_poly_data(qualityFilter.GetOutput(), cell_color_attribute=('Quality', 0.0, 0.83))\n",
    "plot.display()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plot.camera = [95.27, 101.43, 224.85,\n",
    " 53.44, 93.47, 46.74,\n",
    " 0.0, 1.0, 0.0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plot.objects[0].triangles_attribute.shape, plot.objects[0].indices.shape, "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.12"
  },
  "nbTranslate": {
   "displayLangs": [
    "en",
    "pl"
   ],
   "hotkey": "alt-t",
   "langInMainMenu": true,
   "sourceLang": "pl",
   "targetLang": "en",
   "useGoogleTranslate": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
